package com.kedacom.freedomLabel.adapter;

import android.databinding.ViewDataBinding;
import android.graphics.Color;

import com.kedacom.freedomLabel.R;
import com.kedacom.freedomLabel.databinding.ItemGroupLayoutBinding;
import com.kedacom.freedomLabel.model.bean.ItemGroup;
import com.kedacom.lego.adapter.recyclerview.LegoBaseRecyclerViewAdapter;

import java.util.List;

/**
 * @author licheng
 * @since 2019/11/14 14:15
 */
public class ItemGroupAdapter extends LegoBaseRecyclerViewAdapter<ItemGroup> {

    private String mBusinessCategory;

    public ItemGroupAdapter(String businessCategory, List<ItemGroup> data) {
        super(R.layout.item_group_layout, data, com.kedacom.freedomLabel.BR.itemGroup);
        this.mBusinessCategory = businessCategory;
    }

    @Override
    protected void onCustomBindItem(ViewDataBinding binding, int position) {
        ItemGroupLayoutBinding itemBinding = (ItemGroupLayoutBinding) binding;
        ItemGroup itemGroup = getData().get(position);
        itemBinding.itemGroupCategory.setText(String.format("%s-%s", mBusinessCategory, itemGroup.category));
        int count = itemGroup.count;
        if (count > 0) {
            itemBinding.itemGroupCount.setTextColor(Color.BLACK);
            itemBinding.itemGroupCount.setText(String.format("共计%s条", count));
        } else {
            itemBinding.itemGroupCount.setTextColor(Color.RED);
            itemBinding.itemGroupCount.setText("无数据");
        }
    }
}